package myschool.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@WebServlet(value = { "/login","/doLogin2.jsp"},loadOnStartup = 1)
//@WebServlet({ "/login","/doLogin2.jsp"})
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("uname");
        String pass=request.getParameter("upass");
        if(name.startsWith("java82")&&pass.equals("123456")){
            HttpSession session = request.getSession();
            session.setAttribute("USER_LOGIN",name);
            response.sendRedirect("main.jsp");
            return;
        }
        response.getWriter().println("login fail");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
